package com.xmkj.winmoney.home;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.common.Entity.HomeEntity;
import com.common.Entity.SearchEntity;
import com.common.utils.TimeUtils;
import com.common.widget.CountDown.CountdownView;
import com.common.widget.recyclerview.refresh.adapter.CommonAdapter;
import com.common.widget.recyclerview.refresh.adapter.ViewHolder;
import com.xmkj.winmoney.R;
import com.xmkj.winmoney.jifen.JinPaiDetailActivity;

import java.util.List;

public class SearchListAdapter extends CommonAdapter<SearchEntity.ListsBean> {
    public SearchListAdapter(Context context, List<SearchEntity.ListsBean> data) {
        super(context, data);
    }

    @Override
    protected void convert(final ViewHolder holder, final SearchEntity.ListsBean item, int position) {
        CountdownView countdownView = holder.getView(R.id.count_down);
        long time = TimeUtils.getStringToDate(item.remainingdatestr) - Long.valueOf(TimeUtils.getTime());
        countdownView.start(time);
        holder.setImageAvatar(R.id.iv_img, item.goodsthumb);
        holder.setText(R.id.tv_price, item.goodsprice);
        holder.setText(R.id.tv_desc, item.goodsname);
        holder.getParentView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, JinPaiDetailActivity.class);
                HomeEntity.ListsEntity homeEntity =  new HomeEntity.ListsEntity();
                homeEntity.fvid=item.fvid;
                homeEntity.gid = item.gid;
                homeEntity.vid= item.vid;
                intent.putExtra(JinPaiDetailActivity.INFOBEAN, homeEntity);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    protected int getItemViewLayoutId(int position, SearchEntity.ListsBean item) {
        return R.layout.item_home;
    }
}
